package com.rest.demo.functional.strean;

import org.apache.commons.lang.StringUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;

/**
 * @author Administrator
 * @decription 统计java代码量
 * @Date 2018-01-30 13:59
 */
public class CountJava {

    private static Long SUM = 0L;

    private static String JAVA_CHAR = ".java";

    public static void main(String[] args) {
        File file = new File("F:\\guns-framework\\childstory");
        getJavaFileList(file);
        System.out.println(SUM);
    }

    public static void getJavaFileList(File file) {
        if(file.isDirectory()) {
            List<String> fileStrList = Arrays.asList(file.list());
            fileStrList.stream().forEach(f -> getJavaFileList(new File(file.getPath()+"\\"+f)));
        } else {
            if(file.getPath().contains(JAVA_CHAR)) {
                try {
                    SUM += Files.lines(file.toPath())
                            .filter(str -> StringUtils.isNotBlank(str))
                            .count();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
